﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace CommonTools.UserControls.FlowChart
{
    #region 转换器
    public class FlowBoardStatusEnumToBoolConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            FlowBoardStatus status = (FlowBoardStatus)value;
            return status == (FlowBoardStatus)Enum.Parse(typeof(FlowBoardStatus), parameter.ToString()) ? true : false;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool flag = (bool)value;
            if (flag)
                return (FlowBoardStatus)Enum.Parse(typeof(FlowBoardStatus), parameter.ToString());
            else
                return Binding.DoNothing;
        }
    }

    public class NumDivideConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return double.Parse(parameter.ToString()) / (double)value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Binding.DoNothing;
        }
    }

    public class TrueToVisitConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (bool)value == true ? Visibility.Visible : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Binding.DoNothing;
        }
    }

    public class FalseToVisitConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (bool)value == true ? Visibility.Collapsed : Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Binding.DoNothing;
        }
    }

    public class StringToPathConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string name = value.ToString();
            string AppendPath = string.IsNullOrEmpty(parameter.ToString()) ? string.Empty : $"{parameter.ToString()}\\";
            return $"{System.AppDomain.CurrentDomain.BaseDirectory}{AppendPath}{name}.png";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Binding.DoNothing;
        }
    }
    #endregion

    #region 数据类型
    public enum LineDirectionEnum
    {
        左右,
        右左,
        上下,
        下上,
        左上右下,
        右下左上,
        左下右上,
        右上左下,
    }

    public enum DirectionEnum
    {
        上,
        下,
        左,
        右
    }

    public enum FlowBoardStatus
    {
        Browse,
        Link
    }

    public enum FlowItemTypeEnum
    {
        流程,
        判定,
        子流程,
    }


    public class FlowChart_BaseModel : INotifyPropertyChanged
    {
        private long key = Guid.NewGuid().GetHashCode();
        public long Key
        {
            get { return key; }
            set { key = value; OnPropertyChanged(); }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged([CallerMemberName] string strProperty = null)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(strProperty));
            }
        }
    }



    public class Point_Link : FlowChart_BaseModel
    {
        private double x = 0;
        public double X
        {
            get { return x; }
            set { x = value; OnPropertyChanged(); }
        }

        private double y = 0;
        public double Y
        {
            get { return y; }
            set { y = value; OnPropertyChanged(); }
        }

        private int order = 0;
        public int Order
        {
            get { return order; }
            set { order = value; OnPropertyChanged(); }
        }

        public Point_Link(double x, double y)
        {
            X = x;
            Y = y;
        }
    } 

    public class LinkLineModel : FlowChart_BaseModel
    {
        private ObservableCollection<Point_Link> pointList = new ObservableCollection<Point_Link>();
        public ObservableCollection<Point_Link> PointList
        {
            get { return pointList; }
            set { pointList = value; OnPropertyChanged(); }
        }
    }

    public class FlowItemModel : FlowChart_BaseModel
    {
        private FlowItemTypeEnum type = FlowItemTypeEnum.流程;
        public FlowItemTypeEnum Type
        {
            get { return type; }
            set { type = value; OnPropertyChanged(); }
        }

        private string name = string.Empty;
        public string Name
        {
            get { return name; }
            set { name = value; OnPropertyChanged(); }
        }

        private double x = 0;
        public double X
        {
            get { return x; }
            set { x = value; OnPropertyChanged(); }
        }

        private double y = 0;
        public double Y
        {
            get { return y; }
            set { y = value; OnPropertyChanged(); }
        }

        private double height = 30;
        public double Height
        {
            get { return height; }
            set { height = value; OnPropertyChanged(); }
        }

        private double width = 100;
        public double Width
        {
            get { return width; }
            set { width = value; OnPropertyChanged(); }
        }
    }
    #endregion
}
